﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RemoveSVNFolders
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if( folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
                                
                DirectoryInfo dir = new DirectoryInfo(folderBrowserDialog1.SelectedPath);

                DirectoryInfo[] found = dir.GetDirectories(".svn", SearchOption.AllDirectories);

                int dirCount = found.Count();

                if (dirCount > 0)
                {
                    progressBar1.Maximum = dirCount;
                    
                    if (MessageBox.Show("Found: " + dirCount + " dirs. Remove?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        foreach (DirectoryInfo di in found)
                        {
                            try
                            {
                                di.Delete(true);
                                progressBar1.Increment(1);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "Oops");
                                
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("No .svn folders found", "Oops");
                }

                

            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            string target = "http://codesamurai.wordpress.com";
            System.Diagnostics.Process.Start(target);

        }
    }
}
